package logic

import (
	"cart-master/model"
	"context"

	"cart-master/cartrpc/cartrpc"
	"cart-master/cartrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopListLogic {
	return &ShopListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopListLogic) ShopList(in *cartrpc.ShopListRequest) (*cartrpc.ShopListResponse, error) {
	// todo: add your logic here and delete this line

	var shops []model.Shop
	model.DB.Debug().Find(&shops)
	var shopList []*cartrpc.ShopList
	for _, shop := range shops {

		list := cartrpc.ShopList{
			Img:   shop.Img,
			Name:  shop.Name,
			Price: float32(shop.Price),
			Num:   int64(shop.Num),
		}
		shopList = append(shopList, &list)
	}
	return &cartrpc.ShopListResponse{
		List: shopList,
	}, nil
}
